# RAILS ~3.0.5
module ActionView
  module Rendering
    
    # Renders the given template. An string representing the layout can be
    # supplied as well.
    def _render_template(template, layout = nil, options = {}) #:nodoc:
    #  puts "ActionView::Rendering._render_template : #{template.inspect}" 
      locals = options[:locals] || {}
      layout = find_layout(layout) if layout

      ActiveSupport::Notifications.instrument("render_template.action_view",
        :identifier => template.identifier, :layout => layout.try(:virtual_path)) do

        content = template.render(self, locals) { |*name| _layout_for(*name) }
        @_content_for[:layout] = content if layout

        content = _render_layout(layout, locals) if layout
        
        TemplateWrapper::wrap(template.inspect, content)
      end
    end
  end
###################################
  module Partials
  class PartialRenderer
        def render
          #puts "PartialRenderer.render OVERRRIDE"
        identifier = ((@template = find_template) ? @template.identifier : @path)
        if @collection
          ActiveSupport::Notifications.instrument("render_collection.action_view",
            :identifier => identifier || "collection", :count => @collection.size) do
           content =  render_collection
          end
        else
          block, options, locals = @block, @options, @locals

          content = ActiveSupport::Notifications.instrument("render_partial.action_view",
            :identifier => identifier) do
            content = render_partial
          end

          if !block && (layout = options[:layout])
            content = @view._render_layout(find_template(layout), locals){ content }
          end

         TemplateWrapper::wrap(@template.inspect, content) 
        end
      end


    def render_partial(object = @object)
    #puts "PartialRenderer.render_partial OVERRRIDE"
   
        locals, view, template, block = @locals, @view, @template, @block
        #puts "  #{template.inspect}"
        object ||= locals[template.variable_name]
        locals[@options[:as] || template.variable_name] = object
          the_return = template.render(view, locals) do |*name|
          view._layout_for(*name, &block)
        end 
        the_return
    end
    
  end
  end
end
